/**
 * Copyright (c) 2009 blurredVision
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
 * associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 
 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 
 * OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#ifndef __GUI_SLIDER_H__
#define __GUI_SLIDER_H__

#pragma once
#include "Component.h"
#include "Button.h"
#include "IChangeListener.h"

namespace gui {

/**
 * \ingroup coreGUI
 *
 * \date 04-24-2007
 *
 * \author juckel
 *
 * \todo Insert code path for VERTICAL component
 *
 */
class GUI_EXPORT Slider :
	public Component,
	public IChangeObserver,
	public IMouseListener
{
public:
	Slider(void);
	virtual ~Slider(void);

	/// The direction enumeration for drawing the element
	enum eDirection {
		HORIZONTAL,
		//VERTICAL
	};

	/// Set the direction of the slider. Either HORIZONTAL or VERTICAL
	void setDirection(eDirection dir);

	/// Set the range of the slider values
	void setRange(float minVal, float maxVal);

	/// Set the minimum slider value
	void setMinValue(float val);

	/// Set the maximum slider value
	void setMaxValue(float val);

	/// Set the currently selected slider value
	void setCurrentValue(float val);

	/// Process mouse movement
	virtual bool processMouse(int _x, int _y, int _z, int button);

	/// Draw the slider element
	virtual void draw();

	/// Set the dimension of the slider
	void setDimension(int x, int y, int w, int h);

	/// Set the size of the slider
	void setSize(int w, int h);

	/// Enable / Disable drawing of labels
	void setDrawLabels(bool value);

	/// Set the interval between the values
	void setInterval(float value);

	/// Return the minimum value
	const float getMinValue() const;

	/// Return the maximum value
	const float getMaxValue() const;

	/// Return the currently set value
	const float getCurrentValue() const;

	/// Return the interval between values that can be set
	const float getInterval() const;

	/// Set the size of the slider knob
	void setKnobSize(int w, int h);

	/// Return the type of the GUI element
	virtual inline const int getGUIType() const { return GUI_SLIDER; }
	
protected:
	/// Update the position of the slider according to the currently selected value
	void updateSliderOffset();

	/// Callback event from the slider handle
	virtual void onMousePressEvent(const MouseEvent &mevent);
	virtual void onMouseReleaseEvent(const MouseEvent &mevent);

	Button    *m_pKnob;
	float      m_fMinValue;
	float      m_fMaxValue;
	float      m_fInterval;
	float      m_fCurrentValue;
	eDirection m_eDirection;
	float      m_fSliderOffset;
	bool       m_bDragging;
	bool       m_bDrawLabels;
};

} // namespace

#endif
